const os = @import("os");
const std = @import("std");

const SysCall = os.syscall.SysCall;
pub const fd_t = SysCall.fd_t;
pub const pid_t = SysCall.pid_t;
pub const c_str = SysCall.c_str;

pub const O = os.fs.O;
pub const Stat = os.fs.Inode.Stat;
pub const Dirent = os.fs.Inode.Dirent;

comptime {
    for (std.meta.fields(os.syscall.SysTag)) |call| {
        asm (std.fmt.comptimePrint(
                \\.section .text.syscall.{0s}
                \\.global {0s}
                \\{0s}:
                \\ li a7, {1d}
                \\ ecall
                \\ ret
                \\
            , .{ call.name, call.value }));
    }
}

pub fn syscall(comptime name: []const u8) @FieldType(SysCall, name) {
    return @extern(@FieldType(SysCall, name), .{ .name = name });
}

pub const shutdown = syscall("shutdown");
pub const fork = syscall("fork");
pub const getpid = syscall("getpid");
pub const exit = syscall("exit");
pub const wait = syscall("wait");
pub const kill = syscall("kill");
pub const exec = syscall("exec");
pub const getcwd = syscall("getcwd");

pub const access = syscall("access");
pub const open = syscall("open");
pub const close = syscall("close");
pub const fstat = syscall("fstat");
pub const read = syscall("read");
pub const write = syscall("write");
pub const lseek = syscall("lseek");
pub const dup = syscall("dup");
pub const pipe = syscall("pipe");

pub const mknod = syscall("mknod");
pub const link = syscall("link");
pub const unlink = syscall("unlink");
pub const symlink = syscall("symlink");
pub const mkdir = syscall("mkdir");
pub const chdir = syscall("chdir");

pub const pause = syscall("pause");
pub const uptime = syscall("uptime");
pub const sbrk = syscall("sbrk");
pub const trace = syscall("trace");

pub const send = syscall("send");
pub const recv = syscall("recv");
pub const bind = syscall("bind");
pub const unbind = syscall("unbind");
